﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;

namespace LOGIN
{
    public partial class Add : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["name"] == null)
            {
                Response.Redirect("index.aspx");
            }
            else this.login.Text = "" + Session["name"].ToString() + "老师，你已经成功进入登录页面";
        }

        protected void IB_Click(object sender, ImageClickEventArgs e)
        {
            string strCn = "server=pc.hstc.cn;database=dhd2014112122;uid=2014112122;pwd=19950123";
            SqlConnection cn = new SqlConnection(strCn);
            try
            {
                cn.Open();
                string sex = Request.QueryString["sex"];
                if (RadioButton1.Checked)
                {
                    sex = "男";
                }
                else
                {
                    sex = "女";
                }
                string strSql = "INSERT INTO Login (Name, Password, Number, Sex, College) VALUES   (N'" + this.TextBox1.Text + "', N'" + this.TextBox2.Text + "', N'" + this.TextBox4.Text + "',  N'" + sex + "',N'" + this.TextBox5.Text + "')";
                SqlCommand cmd = new SqlCommand(strSql, cn);
                int iUpd = cmd.ExecuteNonQuery();
                if (iUpd < 1)
                {
                    this.lblInfo.Text = "添加失败！";
                }
                else
                {
                    this.lblInfo.Text = "添加成功！";
                }
                Response.Write("<script>alert('您已添加成功。单击“确定”返回。');location.href='Main_Tea.aspx';</script>");
            }
            catch (Exception ex)
            {
                this.lblInfo.Text = ex.Message;
            }
            finally
            {
                cn.Close();
            }
        }
        protected void exit_Click(object sender, EventArgs e)
        {

            Response.Redirect("index.aspx");
        }

        protected void update_Click(object sender, EventArgs e)
        {
            Response.Redirect("Change.aspx");
        }
        protected void tittle_Click(object sender, EventArgs e)
        {
            Response.Redirect("update.aspx");
        }

        protected void information_Click(object sender, EventArgs e)
        {
            Response.Redirect("Information.aspx");
        }
        protected void text_Click(object sender, EventArgs e)
        {

        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Response.Redirect("Add.aspx");
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Session["Theme"] = this.DropDownList1.SelectedValue.ToString();
        }

        protected void Page_PreInit(object sender, EventArgs e)
        {
            if (Session["Theme"] != null)
                this.Theme = Session["Theme"].ToString();
        }
    }
}